package days46.title409;

import java.util.HashMap;

class Solution {
    public int longestPalindrome(String s) {
        boolean flag = false;
        HashMap<Character, Integer> characterIntegerHashMap = new HashMap<>();
        for (int i = 0; i < s.length(); i++) {
            if (characterIntegerHashMap.containsKey(s.charAt(i))) {
                characterIntegerHashMap.put(s.charAt(i), characterIntegerHashMap.get(s.charAt(i)) + 1);
            } else {
                characterIntegerHashMap.put(s.charAt(i), 1);
            }
        }
        int count = 0;
        for (Integer value : characterIntegerHashMap.values()) {
            if (value % 2 == 0) {
                count += value;
            } else {
                flag = true;
                count += value - 1;
            }
        }
        if (flag) {
            count++;
        }
        return count;
    }
}